package org.example.service;


import org.example.domain.Ebook;
import org.example.domain.EbookExample;
import org.example.mapper.EbookMapper;
import org.example.req.EbookReq;
import org.example.resp.EbookResp;
import org.example.util.CopyUtil;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.List;

@Service
public class EbookService {
    @Resource
    private EbookMapper ebookMapper;

    public List<EbookResp> list(EbookReq req) {
        EbookExample example = new EbookExample();
        EbookExample.Criteria criteria = example.createCriteria();
        
        // 构建模糊查询条件
        if (req.getName() != null && !req.getName().trim().isEmpty()) {
            criteria.andNameLike("%" + req.getName() + "%");
        }
        
        // 查询数据库
        List<Ebook> ebookList = ebookMapper.selectByExample(example);
        
        // 使用CopyUtil转换对象
        return CopyUtil.copyList(ebookList, EbookResp.class);
    }
}